﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMSLibrary;
using DataBaseConnection;

public partial class AdminCMS_DataSource_Try : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int sourceid = 0;
        UIMethod.GetQuery(ref sourceid, "sourceid");

        try
        {
            DataEntity.tab_DataSource t = (DataEntity.tab_DataSource)new Cache_DataSource().Cache_getData(sourceid);
            
            if (!t.IsEmpty)
            {
                //Response.Write(t.src_SelectText);

                DataBaseType dbt = DataBaseType.ACCESS;
                if (t.src_IsConfig.Value)
                {
                    t.src_ConnectionString = CSelectDataBase.GetConnectionStrings("DefaultConnection", ref dbt);
                    t.src_DataBaseType = (int)dbt;
                }

                DataSet ds = PublicMethod.GetLocalSourceToTry(t.src_ConnectionString,
                    null, 
                    t.src_SelectText, 
                    t.src_DataBaseType.Value, 
                    10,
                    0);
                
                if (ds != null)
                {
                    GV_source.DataSource = ds.Tables[0].DefaultView;
                    GV_source.DataBind();
                }
            }

        }
        catch(Exception ex)
        {
            Response.Clear();
            Response.Write(ex.Message);
        }
    }
}
